﻿Imports TreeCreeper01Interfaces
Imports System.Collections.Generic

Public Class cPlantCollection

    Private mPlantDictionary As Dictionary(Of String, IPlant)
    ' for faster index based access
    Private mPlantListBaseZero As List(Of IPlant)

    Friend Sub New()
        mPlantDictionary = New Dictionary(Of String, IPlant)
        mPlantListBaseZero = New List(Of IPlant)
    End Sub

    Public Sub Add(ByVal Plant As IPlant)

        mPlantListBaseZero.Add(Plant)
        mPlantDictionary.Add(Plant.UniqueKey, Plant)

    End Sub

    Public ReadOnly Property ItemByIndexBaseOne(ByVal IndexBaseOne As Integer) As IPlant
        Get
            Return mPlantListBaseZero(IndexBaseOne - 1)
        End Get
    End Property

    Public Sub SwapPlantIndices(ByVal PlantOneIndexBaseOne As Integer, ByVal PlantTwoIndexBaseOne As Integer)

        Dim PlantOne As IPlant
        Dim PlantTwo As IPlant

        PlantOne = mPlantListBaseZero(PlantOneIndexBaseOne - 1)
        PlantTwo = mPlantListBaseZero(PlantTwoIndexBaseOne - 1)

        mPlantListBaseZero(PlantOneIndexBaseOne - 1) = PlantTwo
        mPlantListBaseZero(PlantTwoIndexBaseOne - 1) = PlantOne

    End Sub

    Public ReadOnly Property ItemByKey(ByVal Key As String) As IPlant
        Get
            Return mPlantDictionary(Key)
        End Get
    End Property

    Public ReadOnly Property Count() As Integer
        Get
            Return mPlantListBaseZero.Count
        End Get
    End Property

End Class
